package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IFeedbackService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.FeedbackCreateValidate;
import com.mdd.admin.validate.FeedbackUpdateValidate;
import com.mdd.admin.validate.FeedbackSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.FeedbackListedVo;
import com.mdd.admin.vo.FeedbackDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/feedback")
@Api(tags = "意见反馈管理")
public class FeedbackController {

    @Resource
    IFeedbackService iFeedbackService;

    @GetMapping("/list")
    @ApiOperation(value="意见反馈列表")
    public AjaxResult<PageResult<FeedbackListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated FeedbackSearchValidate searchValidate) {
        PageResult<FeedbackListedVo> list = iFeedbackService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="意见反馈详情")
    public AjaxResult<FeedbackDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        FeedbackDetailVo detail = iFeedbackService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "意见反馈新增")
    @PostMapping("/add")
    @ApiOperation(value="意见反馈新增")
    public AjaxResult<Object> add(@Validated @RequestBody FeedbackCreateValidate createValidate) {
        iFeedbackService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "意见反馈编辑")
    @PostMapping("/edit")
    @ApiOperation(value="意见反馈编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody FeedbackUpdateValidate updateValidate) {
        iFeedbackService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "意见反馈删除")
    @PostMapping("/del")
    @ApiOperation(value="意见反馈删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iFeedbackService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
